﻿#include "Renderer/Renderer.h"
#include "Renderer/OpenGL/OpenGLRendererAPI.h" // 假设你用 OpenGL
#include "Camera.h"

namespace Hazel
{
    struct SceneData
    {
        glm::mat4 ViewProjectionMatrix;
    };
    Ref<Shader> Renderer::m_Shader = nullptr;
    static SceneData *s_SceneData = nullptr;

    void Renderer::BeginScene(const Camera &camera)
    {
        s_SceneData->ViewProjectionMatrix = camera.GetProjectionMatrix() * camera.GetViewMatrix();
    }
    // 👇 定义 Renderer 的静态成员
    RendererAPI *Renderer::s_RendererAPI = nullptr;

    // 👇 直接在这里实现 Create() —— 避免遗漏
    RendererAPI *RendererAPI::Create()
    {
        return new OpenGLRendererAPI();
    }

    void Renderer::Init()
    {
        s_RendererAPI = RendererAPI::Create();
        s_RendererAPI->Init();
    }

    void Renderer::Shutdown()
    {
        delete s_RendererAPI;
        s_RendererAPI = nullptr;
    }
    void Renderer::Submit(const Ref<VertexArray> &vertexArray)
    {
        m_Shader->Bind();
        m_Shader->SetMat4("u_ViewProjection", s_SceneData->ViewProjectionMatrix);
        s_RendererAPI->DrawIndexed(vertexArray);
    }
}